home *** CD-ROM | disk | FTP | other *** search
- rem SchPong!
- rem by Scott Mathews
- rem September 20, 1997
- rem thanks to Brad for:
- rem dinner....
- rem inspiration....
- rem and the bouncing ball routine... :)
- rem guess Nolan B deserves some credit
- rem in here too.
-
-
- cls
- inplay = true
- again = false
- Lbuffer = 0
- Rbuffer = 0
-
- rem how many points to win?
- victory = 1
-
- rem beginning player scores
- leftscore = 0
- rightscore = 0
-
- rem keyboard inputs for controlling the paddles
- rem the left player
- lup$ = "w"
- ldown$ = "s"
- lspeed$ = "d"
- lenglish$ = "a"
-
- rem the right player
- rup$ = "i"
- rdown$ = "k"
- rspeed$ = "j"
- renglish$ = "l"
-
- rem playing field size and color
- rem the paddle size and positnio are determined
- rem by the size of the playing field
- rem try playing on a tiny field!
- upperX = 10
- lowerX = 310
- upperY = 25
- lowerY = 230
- fieldcolor = 59
- linecolor = 94
-
- rem paddle size
- padwidth = int((lowerX-upperX)/30)
- padlength = int((lowerY - UpperY)/4)
-
- rem paddle speed
- padspeed = 9
-
- rem ball size, color, maximum speed, maximum engligh
- ballsize = 5
- ballcolor = 3
- maxspeed = 25
- maxenglish = 15
-
- rem paddle direction start values
- Lpaddir = 0
- Rpaddir = 0
-
- rem ball update start values
- balllastX = 10
- balllastY = 10
-
- rem left paddle start position and color
- LpadX = int((lowerX - UpperX)/10)
- LpadY = int((lowerY - UpperY)/2)
- LpadlastY = int((lowerY - UpperY)/2)
- lpadcolor = 54
-
- rem right paddle start position and color
- RpadX = lowerX - LpadX
- RpadY = int((lowerY - UpperY)/2)
- RpadlastY = int((lowerY - UpperY)/2)
- rpadcolor = 150
-
- rem sounds
- hitSnd = LoadSound("Pop")
- bounceSnd = LoadSound("Bounce")
- missSnd = LoadSound("GameShow")
- serveSnd = LoadSound("Payoff")
- endSnd = LoadSound("GamOver1")
-
- rem timer delay for start of service
- startDelay = 1600
-
- rem this color is used to erase the ball and paddles
- backColor = pget (0,0)
-
- gosub intro
- gosub getnames
- startover:
- gosub ballstart
-
- rem the main loop
- while inplay
- cmd$ = Inkey$
-
- rem if you want to quit...
- if cmd$ = "q" then inplay = false
-
- rem assume no movement
- Lpaddir = 0
-
- rem move the left paddle up
- if keydown(Lup$) then
- Lpaddir = -padspeed
- endif
-
- rem move the left paddle down
- if keydown(LDown$) then
- Lpaddir = padspeed
- endif
-
- rem assume no movement
- RpadDir = 0
-
- rem move the right paddle up
- if keydown(rup$) then
- RPaddir = -padspeed
- endif
-
- rem move right paddle down
- if keydown(rdown$) then
- RPadDir = padspeed
- endif
-
- suspendupdate
-
- rem draw the player names and scores
- textcolor 21
- position upperx/8,0
- print name1$;" ";
- print leftscore
- position ((upperX+lowerX)/2)/8,0
- print name2$;" ";
- print rightscore
-
- rem draw the playing field
- color fieldcolor
- rect upperX,upperY to lowerX,lowerY
- color linecolor
- line (upperX+lowerX)/2,upperY to (upperX+lowerX)/2,lowerY
-
- rem draw the ball and its update
- rem if ball not in service timer
- If ballXDir <> 0 then
- color backColor
- fillCircle balllastX,balllastY,ballsize
- color ballcolor
- fillCircle ballx,bally,ballsize
- Else
- Rem count down start timer
- Rem play sound a little before serving
- If Timer() - startTimer > startDelay/2 Then
- If serveSoundPlayed = FALSE Then
- Rem play serving sound
- PlaySound(serveSnd)
- serveSoundPlayed = TRUE
- EndIf
- Endif
-
- Rem serve ball
- If Timer() - startTimer > startDelay Then
- ballXdir = serveXdir
- EndIf
- Endif
-
- rem draw left paddle and its update
- color backcolor
- fillrect LpadX,Lpadlasty to LpadX+padwidth,LpadlastY+padlength
- color lpadcolor
- fillrect LpadX,LpadY to LpadX+padwidth,LpadY+padlength
-
- rem draw right paddle and its update
- color backcolor
- fillrect RpadX,Rpadlasty to RpadX+padwidth,RpadlastY+padlength
- color rpadcolor
- fillrect RpadX,RpadY to RpadX+padwidth,RpadY+padlength
-
- resumeupdate
-
- rem check for collision
- rem left paddle
- If ballLastX > ballX then
- if ballX - ballsize <= Lpadx + padwidth AND ballLastX >= LpadX + padWidth then
- if ballY+ballSize > LpadY and bally-ballSize < LpadY + padlength then
- ballxdir = -ballxdir
- Rem Play hit sound
- PlaySound(hitSnd)
- Rem see if we are applying speed or english modifiers
- If KeyDown(lspeed$) Then ballXDir = ballXDir * 2
- If KeyDown(lenglish$) Then ballYDir = ballYDir + Random(-ballxdir,ballxdir)
- Rem Limit to maximum
- If ballXDir > maxSpeed then ballXDir = maxSpeed
- If ballYDir > maxEnglish then ballYDir = maxEnglish
- If ballYDir < -maxEnglish then ballYDir = -maxEnglish
- endif
- endif
- EndIf
-
- rem right paddle
- If ballLastX < ballX then
- if ballX + ballsize >= Rpadx AND ballLastX <= Rpadx Then
- if ballY+ballSize > RpadY and bally-ballSize < RpadY + padlength then
- ballxdir = -ballxdir
- Rem Play hit sound
- PlaySound(hitSnd)
- if keydown("Shift") then ballYDir = 0
- Rem see if we are applying speed or english modifiers
- If KeyDown(rspeed$) Then ballXDir = ballXDir * 2
- If KeyDown(renglish$) Then ballYDir = ballYDir + Random(ballxdir,-ballxdir)
- Rem Limit to maximum
- If ballXDir < -maxSpeed then ballXDir = -maxSpeed
- If ballYDir > maxEnglish then ballYDir = maxEnglish
- If ballYDir < -maxEnglish then ballYDir = -maxEnglish
- endif
- endif
- EndIf
-
- rem reset the volley for left player
- if ballx > ((upperX+lowerX)/2) then
- Lspeedup = false
- Lenglishup = false
- endif
-
- rem reset the volley for right player
- if ballx < ((upperX+lowerX)/2) then
- rspeedup = false
- renglishup = false
- endif
-
- rem know where to place the ball update
- balllastX = ballx
- balllastY = bally
-
- rem don't let the ball go out of
- rem northern or southern bounds
- if bally < upperY + ballsize or bally > lowerY - ballsize then
- ballyDir = -ballyDir
- Rem play bounce sound
- PlaySound(bounceSnd)
- endif
-
- rem add to the speed of the ball
- ballx = ballx + ballxDir
-
- rem add to the english of the ball
- bally = bally + ballyDir
-
- rem know where to place the paddle update
- LpadlastY = LpadY
- RpadlastY = RpadY
-
- rem move the paddles
- rem check for boundary with playing field first
- rem did the left paddle bonk into the lower boundary?
- if LpadY + padlength - Lbuffer > LowerY - padspeed then
- LpadY = LowerY - padlength
- LPadDir = 0
- Lbuffer = padspeed
- else
- rem did the left paddle bonk into the upper boundary?
- if LpadY + Lbuffer < UpperY + padspeed then
- LpadY = UpperY
- LPadDir = 0
- Lbuffer = padspeed
- else
- rem if it didn't bonk into anything, move it
- LpadY = LpadY + Lpaddir
- Lbuffer = 0
- endif
- endif
-
- rem did the right paddle bonk into the lower boundary?
- if RpadY + padlength - Rbuffer > LowerY - padspeed then
- RpadY = LowerY - padlength
- RPadDir = 0
- Rbuffer = padspeed
- else
- rem did the right paddle bonk into the upper boundary?
- if RpadY + Rbuffer < UpperY + padspeed then
- RpadY = UpperY
- RPadDir = 0
- Rbuffer = padspeed
- else
- rem if it didn't bonk into anything, move it
- RpadY = RpadY + Rpaddir
- Rbuffer = 0
- endif
- endif
-
- rem if the ball goes past the paddle, score a point
- Rem if ballx < LpadX-6 or ballx > RpadX + padwidth+6 then
- If ballx < -ballSize*2 or ballx > 320+ballSize*2 Then
- ballxdir = 0
- Rem play missed ball sound
- PlaySound(missSnd)
- gosub score
- endif
-
- wend
-
- gosub playagain
- if again = true then goto startover
-
- end
-
- rem ball start up values
- ballstart:
- color backcolor
- fillcircle balllastX,balllastY,ballsize
- 'color fieldcolor
- 'rect upperX,upperY to lowerX,lowerY
- ballx = 160
- bally = 120
- let service = random(1,2)
- if service = 1 then serveXDir = 3
- if service = 2 then serveXDir = -3
- ballXDir = 0 ' don't move until timer expires
- ballYDir = 1
- lspeedup = false
- rspeedup = false
- lenglishup = false
- renglishup = false
- Rem Set timer to delay before service
- startTimer = timer()
- serveSoundPlayed = FALSE
-
- return
-
- rem add to the score
- score:
-
- if ballx < (upperx+lowerx)/2 then
- rightscore = rightscore + 1
- endif
-
- if ballx > (upperx+lowerx)/2 then
- leftscore = leftscore +1
- endif
-
- if leftscore = victory then
- position upperx/8,0
- textcolor 100
- print name1$;" ";
- print leftscore
- for I = 20 to 200
- color I
- fillrect LpadX,LpadY to LpadX+padwidth,LpadY+padlength
- inplay = false
- next I
-
- Rem play end of game sound
- Sleep 10
- PlaySound(endSnd)
-
- banner +name1$+" wins!"
- goto endgame
- endif
-
- if rightscore = victory then
- position ((upperX+lowerX)/2)/8,0
- textcolor 100
- print name2$;" ";
- print rightscore
- for I = 20 to 200
- color I
- fillrect RpadX,RpadY to RpadX+padwidth,RpadY+padlength
- inplay = false
- next I
- banner +name2$+" wins!"
- goto endgame
- endif
-
- gosub ballstart
-
- endgame:
- return
-
- intro:
- textcolor 99
- position 10,5
- print "W ";
- sleep 2
- print "E ";
- sleep 2
- print "L ";
- sleep 2
- print "C ";
- sleep 2
- print "O ";
- sleep 2
- print "M ";
- sleep 2
- print "E ";
- print " ";
- sleep 2
- print "T ";
- sleep 2
- print "O";
- sleep 10
-
- cls
- color 21
- fillrect 0,0 to 319,239
- drawtext "@24,BOLD,color 58,helvetica@S" AT 80,70
- drawtext "@48,BOLD,color 27,courier@C" AT 100,75
- drawtext "@16,BOLD,color 220,times@H" AT 135,95
- drawtext "@72,BOLD,color 48,courier@P" AT 150,65
- drawtext "@24,BOLD,color 150,courier@O" AT 200,90
- drawtext "@12,BOLD,color 213,times@N" AT 220,95
- drawtext "@24,BOLD,color 100,helvetica@G" AT 230,100
- drawtext "@12,color 70,Times@by Scott Mathews" AT 118,150
-
- rem big gong sound here
- Sound "TADAA"
- position 13,12
- textcolor 6
- print "Would you like"
- position 10,13
- input "some thrilling info? ", answer$
- if left$(answer$,1) = "y" then
- cls
- color 21
- fillrect 0,0 to 319,239
- position 10,0
- print "You know the score."
- position 11,1
- print "First to ";victory;" wins."
- position 7,2
- print "Here's the keyboard setup:"
- textcolor lpadcolor
- position 0,4
- print "Left Player:"
- position 0,5
- print "paddle up: ";Lup$
- position 0,6
- print "paddle down: ";Ldown$
- position 0,7
- print "add ball speed: ";Lspeed$
- position 0,8
- print "add english: ";Lenglish$
- textcolor rpadcolor
- position 19,4
- print "Right Player:"
- position 19,5
- print "paddle up: ";Rup$
- position 19,6
- print "paddle down: ";Rdown$
- position 19,7
- print "add ball speed: ";Rspeed$
- position 19,8
- print "add english: ";Renglish$
- textcolor 100
- position 15,11
- print "CAUTION:"
- position 7,12
- print "english does wacky things"
- textcolor 6
- position 9,14
- print "Press any key to play"
- while inkey$ <> ""
- wend
- while inkey$ = ""
- wend
- endif
- cls
- return
-
- getnames:
-
- color 21
- fillrect 0,0 to 319,239
- position 0,3
- textcolor lpadcolor
- print " Left Player,"
- input " what is your name? ", name1$
- position 0,8
- textcolor rpadcolor
- print " Right player,"
- input " what is your name? ",name2$
- position 18,12
- textcolor 100
- print "Here ";
- sleep 5
- position 19,13
- print "we"
- sleep 5
- position 19,14
- print "go"
- sleep 5
- cls
- return
-
- playagain:
- position 5,12
- print "Would you like to play again? "
- input " ",answer$
- if left$(answer$,1) = "y" then
- leftscore = 0
- rightscore = 0
- again = true
- inplay = true
- cls
- endif
-
- return
-
-
-
-